package edu.bbu.license.client.android.utility;

import java.util.Random;

/**
 * The password generator.
 */
public class PasswordCreator
{
	/** The number of password components. */
	int components;
	
	/** The random number generator. */
	Random generator;
	
	/** The password components. */
	String passwordComponents;
	
	/**
	 * The constructor.
	 */
	public PasswordCreator()
	{
		this.generator = new Random();
		this.passwordComponents = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
		this.components = passwordComponents.length();
	}
	
	/**
	 * Generation the password.
	 * @param length the password length.
	 * @return the generated password.
	 */
	public String generatePassword(int length)
	{
		StringBuilder answer = new StringBuilder(length);
		
		for(int i = 0; i < length; i++)
		{
			answer.append(passwordComponents.charAt(generator.nextInt(components)));
		}
		
		return answer.toString();
	}
}
